<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        //1、变量定义
        var r = 2, pi=3.14;
        document.write("半径为2的圆的面积为："+pi * r * r +"<br/>");

        //2、函数
        function area() {
            return pi * r * r;
        }
        document.write("半径为2的圆的面积为："+area() + "<br/>");

        function sum(a,b) {
            return a+b;
        }
        document.write("a+b的和为："+sum(3,6) + "<br/>");

        //3、if语句 while语句/for语句
        function whileTest() {
            var i=1;
            var count = 0;
            while(i<10){
                if(i % 2 === 0){
                    count ++ ;
                }
                i++;
            }
            return count;
        }

        document.write("while循环得到的偶数："+whileTest() + "<br/>");

        function forTest() {
            var count = 0;
            for(var j=1;j<10;j++){
                if(j % 2 !== 0){
                    count ++;
                }
            }
            return count;
        }

        document.write("奇数循环得到的奇数："+forTest() + "<br/>");

    </script>
</head>
<body>

</body>
</html>